Repository navigation
fix(server): the Claude usage calendar keeps days after Claude deletes its files - #1053
Merged
Merged
Conversation
…s its files The Local token activity calendar for Claude only reached back about a month. It is built from Claude Code's transcript files, which Claude Code deletes cleanupPeriodDays (30 by default) after they were last written. Threadlines meant to keep its own rolling year in the provider status cache, but a restart's pending snapshot (sign-in unknown, no history) replaced it, and dev servers share that cache folder. Each read now folds its daily totals into a saved history file in the server's state folder (one per Claude folder). A day keeps the larger of what was saved and what was read, so a deleted transcript no longer lowers or erases it. Every reader of one file shares a lock and re-reads the file before saving, so two instances of one folder can't overwrite each other. A file this build can't read is left alone. The reader also takes the larger of Claude's stats cache and the scan for each day instead of replacing the cache's days, keeps saved days when the scan is incomplete, and computes the lifetime total so it never drops when a transcript is deleted.
|
The latest updates on your projects. Learn more about Vercel for GitHub. 1 Skipped Deployment
|
This branch was previously deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The Claude "Local token activity" calendar in Settings > Providers > Usage only reached back about a month. It's built from Claude Code's transcript files, and Claude Code deletes those
cleanupPeriodDays(30 by default) after they were last written. Threadlines meant to keep its own rolling year in the provider status cache, but every restart wiped it: the pending snapshot (sign-in unknown, no token history) replaced the saved one, and dev servers share that cache folder.Each read now folds its daily totals into a saved history file under the server's state folder (
provider-token-history/claude-<hash>.json, one per Claude folder). A day keeps the larger of what was saved and what was read, so a deleted transcript can't lower or erase it. All readers of one file share a lock and re-read the file before saving, so two instances of one folder can't overwrite each other from stale copies. A file this build can't read is left alone, and a failed save is retried on the next read.The reader also:
Codex isn't affected: its calendar comes from OpenAI's servers.
Days deleted before this ships can't be recovered. The calendar fills toward a full year from here.
Tested with a new case in
ProviderRegistry.test.ts: two readers of one folder, a transcript deleted between them, and the saved file checked afterwards. It fails without the store. Format, lint and typecheck pass, and the related server test files pass (160 tests).